/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ejemplojavafx;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import mx.edu.itschapala.sistemas.septimo.control.ProductoLnLista;
import mx.edu.itschapala.sistemas.septimo.control.ProductoLnLocal;
import mx.edu.itschapala.sistemas.septimo.modelo.Producto;

/**
 * FXML Controller class
 *
 * @author snake_gt
 */
public class RegistroProductoController implements Initializable {

    @FXML
    private AnchorPane ventana;
    @FXML
    private TextField codigo;
    @FXML
    private TextField nombre;
    @FXML
    private TextField precio;
    @FXML
    private TextField departmento;
    @FXML
    private TextField descripcion;
    
    @FXML
    public void ventanaListarProducto(){
        try{
            Parent root = FXMLLoader.load(getClass().getResource("ListarProducto.fxml"));
            ventana.getScene().setRoot(root);
        }catch(Exception e){
            System.out.println("Error al cargar la vista");
        }
    }
    
    
    @FXML
    public void registrarProducto(){
        Producto p = new Producto(
                Integer.parseInt(codigo.getText()),
                nombre.getText(), 
                Float.parseFloat(precio.getText()), 
                departmento.getText(), 
                descripcion.getText()
                );
        
        ProductoLnLocal pln = ProductoLnLista.getInstancia();
        pln.registrar(p);
        
    }
    
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }    
    
}
